package net.dlz.example.service;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import net.dlz.example.domain.*;
import net.dlz.example.mapper.DistrictMapper;
import net.dlz.example.mapper.DoorMapper;
import net.dlz.example.mapper.StreetMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class DoorServiceImpl  implements DoorService{
    @Autowired
    private DoorMapper doorMapper;
    @Autowired
    private DistrictMapper districtMapper;
    @Autowired
    private StreetMapper streetMapper;


    @Override
    public SearchDoorResponse listDoor(Integer pageSize, Integer pageNum) {

        PageHelper.startPage(pageNum,pageSize);
        List<Door>doors= doorMapper.selectByExample(new DoorExample());
        return  new SearchDoorResponse(((Page)doors).getTotal(),doors);
    }

    @Override
    public Door findDoorByPrimaryKey(String id) {
        return doorMapper.selectByPrimaryKey(id);
    }




    @Override
    public int saveDoor(Door door) {
       if (StringUtils.isNotBlank(door.getDoorId())){
         return doorMapper.updateByPrimaryKey(door);
       }else {
           return  doorMapper.insert(door);
       }
    }

    @Override
    public int deleteDoorByPrimsryKey(String id) {
        return doorMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Door> findAllDoor() {
        return doorMapper.selectByExample(new DoorExample());
    }

//
//    @Override
//    public List<Door> findLngLat(String lng, String lat) {
//        return doorMapper.findLngLat(lng,lat);
//    }

    @Override
    public List<Door> getByLatitudeandLongitude() {
        return doorMapper.findLngLat();

    }


    @Override
    public List<District> getAllDistrict() {
        return districtMapper.selectAllDistrict();
    }

    @Override
    public List<Street> getStreetByDistrictId(String id) {
        return streetMapper.getStreetByDistrictId(id);
    }

    @Override
    public List<Door> getDoorByStreetId(String id) {
        return doorMapper.getDoorByStreetId(id);
    }

    @Override
    public List<Door> streetDoor(String streetName) {
        return doorMapper.streetDoor(streetName);
    }
@Override
    public  List<Door> selectdoorByType(Integer type){
        return  doorMapper.selectdoorByType(type);
}


}
